package org.origin.ferret.system.mapstruct;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.origin.centre.support.utils.EnumUtil;
import org.origin.ferret.system.model.dto.user.SysUserInsertDto;
import org.origin.ferret.system.model.dto.user.SysUserUpdateDto;
import org.origin.ferret.system.model.entity.SysUserEntity;
import org.origin.ferret.system.model.enums.UserGenderEnum;
import org.origin.ferret.system.model.enums.UserStatusEnum;
import org.origin.ferret.system.model.vo.user.SysUserVo;

/**
 * 系统用户对象-转换
 * SysUserMapstruct INSTANCE = Mappers.getMapper(SysUserMapstruct.class);
 * @author ferret
 * @version 2024-05-08
 */
@Mapper(componentModel = "spring")
public interface SysUserMapstruct {

    SysUserEntity toEntity(SysUserInsertDto insertDto);

    SysUserEntity toEntity(SysUserUpdateDto updateDto);

    @Mapping(target = "genderLabel", expression = "java(getGenderLabel(entity.getGender()))")
    @Mapping(target = "statusLabel", expression = "java(getStatusLabel(entity.getStatus()))")
    SysUserVo toVo(SysUserEntity entity);

    default String getGenderLabel(Integer gender) {
        return EnumUtil.getTitle(UserGenderEnum.class, gender);
    }

    default String getStatusLabel(Integer status) {
        return EnumUtil.getTitle(UserStatusEnum.class, status);
    }
}
